package com.sx.zongzhi.activity;

import android.os.Bundle;
import android.support.annotation.IdRes;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Spinner;

import com.sx.zongzhi.BaseActivity;
import com.sx.zongzhi.R;
import com.sx.zongzhi.adapter.SpinnerPubAdapter;
import com.sx.zongzhi.bean.GlobalBean;
import com.sx.zongzhi.bean.MsgEvent;
import com.sx.zongzhi.bean.PublicBean;
import com.sx.zongzhi.bean.SocietyOrganizionBean;
import com.sx.zongzhi.presenter.PublicListPest;
import com.sx.zongzhi.utils.MyRxBus;
import com.sx.zongzhi.utils.ToastUtils;
import com.sx.zongzhi.view.IPublicBeanView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 搜索新社会组织
 * Created by admin on 2017/12/9.
 */

public class NewSocietyOrganizationSearchActivity extends BaseActivity implements IPublicBeanView {


    @BindView(R.id.et_name)
    EditText etName;
    @BindView(R.id.sp_type)
    Spinner spType;
    @BindView(R.id.et_registrationNumbers)
    EditText etRegistrationNumbers;
    @BindView(R.id.et_registrationManagementCode)
    EditText etRegistrationManagementCode;
    @BindView(R.id.et_unifiedSocialCreditCode)
    EditText etUnifiedSocialCreditCode;
    @BindView(R.id.et_legalPerson)
    EditText etLegalPerson;
    @BindView(R.id.et_legalPersonMobileNumber)
    EditText etLegalPersonMobileNumber;
    @BindView(R.id.et_legalPersonTelephone)
    EditText etLegalPersonTelephone;
    @BindView(R.id.et_legalSafePerson)
    EditText etLegalSafePerson;
    @BindView(R.id.et_legalSafePersonMobileNumber)
    EditText etLegalSafePersonMobileNumber;
    @BindView(R.id.et_legalSafePersonTelephone)
    EditText etLegalSafePersonTelephone;
    @BindView(R.id.et_moneySource)
    EditText etMoneySource;
    @BindView(R.id.rg_isHaveOverSea)
    RadioGroup rgIsHaveOverSea;

    private List<GlobalBean> style;

    private PublicListPest publicListPest;
    private int isSea = 1;

    @Override
    public void setUI(Bundle savedInstanceState) {
        setContentView(R.layout.activity_sear_society);
        setTitleName("非公有制经济组织搜索");
        ButterKnife.bind(this);
        setTitleRight("确定");

        publicListPest = new PublicListPest(this);
        publicListPest.getPublicList("社会组织类型");
        rgIsHaveOverSea.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
                if (group.getId() == R.id.rg_isHaveOverSea){
                    if (checkedId ==  R.id.rbt_Yes){
                        isSea = 1;
                    }else if (checkedId ==  R.id.rbt_No){
                        isSea = 0;
                    }
                }
            }
        });
    }

    @OnClick({R.id.tv_right})
    public void OnClick(View view) {
        switch (view.getId()) {
            case R.id.tv_right:
                subMit();
                break;
        }
    }

    private void subMit() {
        SocietyOrganizionBean bean = new SocietyOrganizionBean();
        if (spType.getSelectedItem() != null) {
            bean.typeId = ((GlobalBean) spType.getSelectedItem()).getId();
        }
        bean.name = etName.getText().toString().trim();
        bean.registrationManagementCode = etRegistrationManagementCode.getText().toString().trim();
        bean.unifiedSocialCreditCode = etUnifiedSocialCreditCode.getText().toString().trim();
        bean.registrationNumber = etRegistrationNumbers.getText().toString().trim();
        bean.legalPerson = etLegalPerson.getText().toString().trim();
        bean.legalPersonMobileNumber = etLegalPersonMobileNumber.getText().toString().trim();
        bean.legalPersonTelephone = etLegalPersonTelephone.getText().toString().trim();
        bean.legalSafePerson = etLegalSafePerson.getText().toString().trim();
        bean.legalSafePersonMobileNumber = etLegalSafePersonMobileNumber.getText().toString().trim();
        bean.legalSafePersonTelephone = etLegalSafePersonTelephone.getText().toString().trim();
        bean.moneySource = etMoneySource.getText().toString().trim();
        bean.legalSafePersonTelephone = etLegalSafePersonTelephone.getText().toString().trim();
        bean.haveOverSea = isSea;
        MyRxBus.get().post(new MsgEvent("NewSocietyOrganizationActivity", 2, bean));
        finish();
    }

    @Override
    public void getPublicList(PublicBean publicBean) {
        if ("社会组织类型".equals(publicBean.getDomainName())) {
            style = publicBean.getDicts();
            if (style != null) {
                SpinnerPubAdapter adapter = new SpinnerPubAdapter(this, R.layout.item_text, style);
                spType.setAdapter(adapter);
            }
        }
    }

    @Override
    public void showError(String message) {
        ToastUtils.showToast(NewSocietyOrganizationSearchActivity.this, message);
    }

}
